package gameObjects;

import java.io.IOException;

import logic.Coords2D;

import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Capsule;

public class Pill extends Object3D{
	private static final long serialVersionUID = 2304100141L;
	private Coords2D coords;
	
	public Pill(Coords2D coords) throws IOException
	{
		super(coords.toString());
		this.coords=coords;
		this.Place(coords.getX()+0.5f, 0.5f, coords.getY()+0.5f);
		makePill();
		this.addTexture();
	}
	
	private void addTexture()
	{
		String[] texPath = {"textures/pill_red.png","textures/pill_yellow.png","textures/pill_green.png"};
		this.texture.setTexture(texPath[1], new Vector3f(1, 1, 1), false);
		this.texture.setTextureManager(this);
	}
	
	private void Place(float x, float y, float z)
	{
		this.setLocalTranslation(x, y, z);
	}
	
	public void update(float tpf)
	{
		Quaternion rot = new Quaternion();
        Vector3f axis = new Vector3f( 0, 1, 0 ).normalizeLocal();
		rot.fromAngleNormalAxis( 5.5f * tpf, axis );
		this.getLocalRotation().multLocal(rot);
	}
	
	private void makePill()
	{
		int axisSample   = 6;
		int radialSample = 6;
		int sphereSample = 6;
		float radius     = 0.2f;
		float height	 = 0.5f;
		Capsule c = new Capsule("PILL",axisSample,radialSample,sphereSample,radius,height);
		c.setCastsShadows(true);
		c.getLocalRotation().fromAngleAxis((float)Math.PI/4, Vector3f.UNIT_Z);
		super.attachChild(c);
	}
	
	public Coords2D getCoords()
	{
		return coords;
	}
}
